package com.tudouji.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.system.domain.Tuser;
import com.tudouji.project.system.service.ITuserService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 用户Controller
 * 
 * @author wf
 * @date 2020-12-29
 */
@RestController
@RequestMapping("/system/tuser")
public class TuserController extends BaseController
{
    @Autowired
    private ITuserService tuserService;

    /**
     * 查询用户列表
     */
    @PreAuthorize("@ss.hasPermi('system:tuser:list')")
    @GetMapping("/list")
    public TableDataInfo list(Tuser tuser)
    {
        startPage();
        List<Tuser> list = tuserService.selectTuserList(tuser);
        return getDataTable(list);
    }

    /**
     * 导出用户列表
     */
    @PreAuthorize("@ss.hasPermi('system:tuser:export')")
    @Log(title = "用户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Tuser tuser)
    {
        List<Tuser> list = tuserService.selectTuserList(tuser);
        ExcelUtil<Tuser> util = new ExcelUtil<Tuser>(Tuser.class);
        return util.exportExcel(list, "tuser");
    }

    /**
     * 获取用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:tuser:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(tuserService.selectTuserById(guid));
    }

    /**
     * 新增用户
     */
    @PreAuthorize("@ss.hasPermi('system:tuser:add')")
    @Log(title = "用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Tuser tuser)
    {
        return toAjax(tuserService.insertTuser(tuser));
    }

    /**
     * 修改用户
     */
    @PreAuthorize("@ss.hasPermi('system:tuser:edit')")
    @Log(title = "用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Tuser tuser)
    {
        return toAjax(tuserService.updateTuser(tuser));
    }

    /**
     * 删除用户
     */
    @PreAuthorize("@ss.hasPermi('system:tuser:remove')")
    @Log(title = "用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(tuserService.deleteTuserByIds(guids));
    }


    @GetMapping("/tuserList")
    public AjaxResult tuserList(Tuser tuser)
    {
        List<Tuser> list = tuserService.selectTuserList(tuser);
        return AjaxResult.success(list);
    }
}
